<template>
	<view class="content">
		<view class="info-block">
			<template v-if="list.length>0">
				<view class="info-item" v-for="(item,index) in list" :key="item.id">
					<view class="title-item">
						<view class="name">工作任务</view>
						<view class="total-item">
							<view class="status3" v-if="item.status===1">
								<view class="round"></view>
								<view class="text">已完成</view>
							</view>
							<view class="status2" v-else-if="item.status===2">
								<view class="round"></view>
								<view class="text">未完成</view>
							</view>
							<view class="status" v-else-if="item.status===3">
								<view class="round"></view>
								<view class="text">正在开展</view>
							</view>
						</view>
					</view>
					<view class="text-block">
						<view class="text-content" :class="item.more?'':'fewer'">{{item.task}}</view>
						<view class="more" @click="list[index].more=!item.more">{{item.more?'收起':'展开'}}</view>
					</view>
					<view class="name">进展情况</view>
					<view class="text-block">
						<view class="text-content">{{item.evolve}}</view>
					</view>
				</view>
			</template>
			<template v-else>
				<view class="info-item">
					<view class="title-item">
						<view class="name">工作任务</view>
						<view class="total-item">
							<view class="status3" v-if="info.status===1">
								<view class="round"></view>
								<view class="text">已完成</view>
							</view>
							<view class="status2" v-else-if="info.status===2">
								<view class="round"></view>
								<view class="text">未完成</view>
							</view>
							<view class="status" v-else-if="info.status===3">
								<view class="round"></view>
								<view class="text">正在开展</view>
							</view>
						</view>
					</view>
					<view class="text-block">
						<view class="text-content" :class="more?'':'fewer'">{{info.task}}</view>
						<view @click="more=!more" class="more">{{more?'收起':'展开'}}</view>
					</view>
					<view class="name">进展情况</view>
					<view class="text-block">
						<view class="text-content">{{info.evolve}}</view>
					</view>
				</view>
			</template>
		</view>
	</view>
</template>

<script>
	import {
		selectKeyWorkById
	} from '@/api/search.js'
	export default {
		data() {
			return {
				info: {},
				more: false,
				list: [],
				departmentId: 0,
				id: 0
			}
		},
		methods: {
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			getList() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				selectKeyWorkById({
					id: this.id,
					departmentId: this.departmentId
				}).then(data => {
					uni.hideLoading()
					if (this.departmentId == 0) {
						this.info = data
					} else {
						let list = data || [];
						list.forEach((item, index) => {
							item.more = false;
						})
						this.list = list
					}
				}).catch(() => {
					uni.hideLoading()
				})
			}
		},
		onLoad(e) {
			console.log(e)
			if (e.departmentId != 'undefined') {
				this.id = 0
			} else {
				this.id = e.id
			}
			if (e.departmentId == 'undefined') {
				this.departmentId = 0
			} else {
				this.departmentId = e.departmentId
			}
			console.log(this.departmentId)
			this.getList()
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background: #F5F5F5;
		width: 100%;
		min-height: 100vh;


		.info-block {
			min-height: 80vh;
			display: flex;
			flex-direction: column;
			background: #F5F5F5;
			border-radius: 40rpx;
			height: auto;
			position: relative;
			padding: 30rpx;


			.info-item {
				width: 100%;
				height: auto;
				box-shadow: 0 0 10px 0 #dedede;
				background: #fff;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				border-radius: 20rpx;
				padding: 30rpx;
				margin-bottom: 30rpx;
				//align-items: center;

				.title-item {
					width: 100%;
					display: flex;
					flex-direction: row;
					justify-content: space-between;

					.name {
						font-weight: bold;
						font-size: 32rpx;
					}

					.total-item {
						display: flex;
						flex-direction: column;
						align-items: center;

						.money {
							font-weight: bold;
							font-size: 34rpx;
						}

						.text {
							font-size: 28rpx;
							color: #999;
							margin-top: 10rpx;
						}

						.status {
							display: flex;
							flex-direction: row;
							align-items: center;

							.round {
								width: 30rpx;
								height: 30rpx;
								border-radius: 50%;
								background-color: #EF731B;
								margin-top: 10rpx;
								margin-right: 10rpx;
							}

							.text {
								font-size: 28rpx;
								color: #EF731B;
								font-weight: 600;
							}
						}

						.status2 {
							display: flex;
							flex-direction: row;
							align-items: center;

							.round {
								width: 30rpx;
								height: 30rpx;
								border-radius: 50%;
								background-color: #E30302;
								margin-top: 10rpx;
								margin-right: 10rpx;
							}

							.text {
								font-size: 28rpx;
								color: #E30302;
								font-weight: 600;
							}
						}

						.status3 {
							display: flex;
							flex-direction: row;
							align-items: center;

							.round {
								width: 30rpx;
								height: 30rpx;
								border-radius: 50%;
								background-color: #029602;
								margin-top: 10rpx;
								margin-right: 10rpx;
							}

							.text {
								font-size: 28rpx;
								color: #029602;
								font-weight: 600;
							}
						}
					}
				}

				.name {
					margin-top: 20rpx;
					font-weight: bold;
					font-size: 32rpx;
				}

				.text-block {
					flex-direction: column;
					color: #000;
					background-color: #F5F5F5;
					padding: 20rpx;
					margin-top: 30rpx;
					border-radius: 20rpx;

					.text-content {
						font-size: 30rpx;
						text-align: justify;
						line-height: 1.8;
					}

					.text-content.fewer {
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 3;
						overflow: hidden;
					}

					.more {
						color: $uni-color-primary;
						font-size: 30rpx;
						text-align: right;
					}
				}
			}
		}
	}
</style>